import java.security.MessageDigest;
import java.security.*;
import java.util.Random;

/**
 * <p>Title: Auth </p>
 *
 * <p>Description: fonctions utiles pour l'authentification</p>
 *
 * <p>Copyright: (c) 2008 FSSIM</p>
 *
 * <p>Company: FSSImock</p>
 *
 * @author Antoine Farnault
 * @author Augustin Couette
 * @version 1.0
 */
public class Auth {
	private static byte[] hash(byte[] s) throws NoSuchAlgorithmException{
		MessageDigest md;
		md = MessageDigest.getInstance("MD5");
		md.update(s);
		return md.digest();
	 }
	 
	 public static byte[] compute(String seed, String password, int sequence) throws NoSuchAlgorithmException{
		 byte[] m = (seed+password).getBytes();
		 for (int i = 0; i < sequence; i++) {
			 m = hash(m);
		 }
		 return m;
	 }
	 
	 public static String makeSeed(){
		 SecureRandom r = new SecureRandom();
		 return r.generateSeed(16).toString();
	 }
	 
	 public static int makeSequence(){
		 Random r = new Random();
		 return (r.nextInt(500)+200);
	 }
}
